#include <bits/stdc++.h>
using namespace std;
int r,c,cnt = 0;
char a[1005][1005];
void dfs(int x,int y) {
	if(x > r||x < 1||y > c||y < 1||a[x][y] == '.') return;
	a[x][y] = '.';
	dfs(x,y+1);
	dfs(x-1,y);
	dfs(x,y-1);
	dfs(x+1,y);
}
bool check(int x,int y) {
	int s=0;
	if(a[x][y]=='#') s++;
	if(a[x+1][y]=='#') s++;
	if(a[x][y+1]=='#') s++;
	if(a[x+1][y+1]=='#') s++;
	return s==3;
}

int main() {
	cin >> r >> c;
	for(int i = 1; i <= r; i++) {
		for(int j = 1; j <= c; j++) {
			cin >> a[i][j];
		}
	}
	for(int i = 1; i <= r; i++) {
		for(int j = 1; j <= c; j++) {

			if(check(i,j)) {
				cout << "Bad placement.";
				return 0;
			}

		}
	}
	for(int i = 1; i <= r; i++) {
		for(int j = 1; j <= c; j++) {
			if(a[i][j] == '#') {
				dfs(i,j);
				cnt++;
			}
		}
	}
	printf("There are %d ships.",cnt);
	return 0;
}
